package pl.perseus.action;

import lombok.Getter;
import lombok.Setter;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import pl.perseus.model.Rach;
import pl.perseus.service.exception.TransferException;
import pl.perseus.service.rach.IRachService;

public class TransferAction extends BaseAction {

	@Autowired
	IRachService rachService;
	
	@Getter
	@Setter
	Long cash;
	
	@Getter
	@Setter
	Rach out;
	
	@Getter
	@Setter
	Rach incoming;
	
	@Getter
	@Setter
	String title;
	
	@Getter
	@Setter
	String receiverName;
	
	@Getter
	@Setter
	String confirmationCode;
	
	@Override
	public String execute() {
		try {
			if(receiverName == null || receiverName.isEmpty()) receiverName = "Inner";
			rachService.transfer(out, incoming, cash, title, receiverName, confirmationCode);
		} catch (TransferException e) {
			Logger.getLogger(TransferAction.class).log(Level.ERROR, e.getMessage());
		}
		
		return SUCCESS;
	}

}
